package cc.rengu.redp.common.render.dict.sources;

import cc.rengu.redp.system.domain.Dict;
import cc.rengu.redp.system.service.CommonDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DefaultDictData implements DictData {

    @Autowired
    private CommonDictService commonDictService;

    @Override
    public Map<String, Map<String, String>> getAllDictData() {
        List<Dict> dicts = commonDictService.list();
        Map<String, Map<String, String>> dictMap = new HashMap<>();
        dicts.forEach( dict -> {
            Map<String, String> kvMap = dictMap.get(dict.getFieldName());
            if (kvMap == null){
                kvMap = new HashMap<>();
                dictMap.put(dict.getFieldName(), kvMap);
            }

            kvMap.put(dict.getKeyy(), dict.getValuee());
        });

        return dictMap;
    }
}
